home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS03.ADF / C / chop.c < prev    next >
Text File  |  1986-04-02  |  3KB  |  80 lines

  1. /**************************************************************************
  2.  * filefix vers 1.0  - designed to run under CLI only                     *
  3.  *                                                                        *
  4.  * (c) 1986 by Techni Soft - Technical Software for the AMIGA             *
  5.  *                                                                        *
  6.  * 24 hour data line and BBS  (801) 264-8290                              *
  7.  *                                                                        *
  8.  * This trivial program released to the public domain  05Jan86            *
  9.  *                                                                        *
  10.  **************************************************************************/
  11.  
  12.  
  13. #include <exec/types.h>
  14. #include <stdio.h>
  15. #include <ctype.h>
  16. #include <libraries/dos.h>
  17.  
  18.  
  19. main(argc,argv)
  20. int argc;
  21. char *argv[];
  22.  
  23. {
  24.    FILE  *inp,*outp;    /* input and output file pointers */
  25.    int   filesize,      /* size to chop to                */
  26.          r;             /* i/o character and status       */
  27.    LONG  count=0;       /* count of bytes output          */
  28.  
  29. /*****************************
  30.  * see if we got enough args *
  31.  *****************************/
  32.  
  33.    if( argc != 3 )
  34.    {
  35.       printf("\n\nusage: filefix <fromfile> <tofile>\n\n",argc);
  36.       exit(FALSE);
  37.    }
  38.  
  39. /********************************************************************
  40.  * attempt to open the input and (create if needed) the output file *
  41.  ********************************************************************/
  42.  
  43.    if( (inp = fopen(argv[1], "r")) == NULL)
  44.    {
  45.       printf("\n\nerror opening input file  [%s]\n\n ",argv[1]);
  46.       exit(FALSE);
  47.    }
  48.    if( (outp = fopen(argv[2], "w")) == NULL)
  49.    {
  50.       printf("\n\nerror opening output file  [%s]\n\n",argv[2]);
  51.       fclose(inp);
  52.       exit(FALSE);
  53.    }
  54.    printf("\nenter file size :");
  55.    scanf("%d",&filesize);
  56.    printf("\nchopping file to %d bytes\n",filesize);
  57.  
  58. /***********************************************************
  59.  * read input and write output for the specified number    *
  60.  * of bytes.  Notice that NO error checking is done here   *
  61.  * except for EOF condition on input file....              *
  62.  *                                                         *
  63.  * note that an assumption is also being made that the     *
  64.  * two I/O function are feeding us raw characters (i.e     *
  65.  * a CR/LF pair is NOT being xlated to a single \n char)   *
  66.  ***********************************************************/
  67.  
  68.  
  69.    while(( ( r = fgetc(inp)) != EOF) && ++count <= filesize)
  70.    {
  71.       fputc( r, outp);
  72.       if(! count % 1024)
  73.          printf("+");
  74.       if(! count % 10240)
  75.          printf("\n");
  76.     }
  77.     fclose(inp);
  78.     fclose(outp);
  79. }
  80.